package com.yb.framework.core.handler;

import java.nio.file.AccessDeniedException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yb.framework.core.domain.AjaxObject;

/**
 * 全局异常处理
 */
@ControllerAdvice
public class GlobalExceptionHandler {
	
	Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
	
	@ResponseBody 
	@ExceptionHandler(Exception.class)
	public AjaxObject handleException(Exception e) {
		logger.error(e.getMessage(), e);
		return AjaxObject.newError();
	}
	
	@ResponseBody
	@ExceptionHandler(AccessDeniedException.class)
	public AjaxObject handleException(AccessDeniedException e) {
		logger.error(e.getMessage(), e);
		return AjaxObject.newError();
	}
}
